<?php

// No direct access
defined ('_JEXEC') or die();

jimport ('joomla.application.component.modeladmin');

class ShipnhanhModelNotification extends JModelAdmin
{
	public function getForm($data = array(), $loadData = true)
	{
		// Get form
		$form = $this->loadForm('com_shipnhanh.notification', 'notification', array('control' => 'jform', 'load_data' => $loadData));
		
		if (! $form)
		{
			return false;
		}
		else
		{
			return $form;
		}
	}
	
	public function loadFormData()
	{
		$data = $this->getItem();
		
		return $data;
	}
	
	public function insert($orderid, $note)
	{
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
		$user = JFactory::getUser();
		
		$columns = array('userid', 'date', 'orderid', 'note');
		$values = array($user->id, 'now()', $orderid, $db->quote($note));
		
		$query->insert('#__sn_notifications');
		$query->columns($db->quoteName($columns));
		$query->values(implode(',', $values));
		
		$db->setQuery($query);
		
		if (!$db->query())
		{
			JError::raiseError(500, $db->getErrorMsg());
			return false;
		}
		else
		{
			return true;
		}
	}
}